package com.design3.graduatethesissys.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.design3.graduatethesissys.common.utils.FileUtil;
import com.design3.graduatethesissys.common.utils.GetUserName;
import com.design3.graduatethesissys.domain.PingJia;
import com.design3.graduatethesissys.service.ChuqiService;

@Controller
@RequestMapping(value = "/Student")
public class Chuqi {
	
	@Autowired
	ChuqiService chuqiService;
	
	@RequestMapping(value = "/Chuqi")
	public String Chuqi(ModelMap data){
	    data.addAttribute("info",1);
	    return "Student/Chuqi";
	}
	
	@RequestMapping(value = "/Zhongqi")
	public String Zhongqi(ModelMap data){
	    data.addAttribute("info",1);
	    return "Student/Zhongqi";
	}
	
	@RequestMapping(value = "/Zongjie")
	public String Zongjie(ModelMap data){
	    data.addAttribute("info",1);
	    return "Student/Zongjie";
	}
	
	@RequestMapping(value = "/Password")
	public String Password(ModelMap data){
	    data.addAttribute("info",1);
	    return "Student/Password";
	}
	
	@RequestMapping(value = "/Chuqi/selectAll")
	@ResponseBody
	public List<PingJia> chuQiList(@RequestParam("pjstatus")String pj_status){
		System.out.println("asda4s56fasd64d68s4fads658f4");
		String stu_id = GetUserName.getUserName();
		System.out.println(chuqiService.chuQiList(stu_id,pj_status));
		return chuqiService.chuQiList(stu_id,pj_status);
	}
	/**
	 * 上传或更新，stu_status表明是初期还是中期等，用pj01/02/03
	 * @param sbj_status
	 * @param file
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/uploadChuqi")
	public Map<String, Object> uploadChuqi(MultipartFile file) {
		String stu_id = GetUserName.getUserName();
		String result = FileUtil.upload(file, stu_id, "pj01");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("message", result);
		return map;
	}
	
	@ResponseBody
	@RequestMapping(value = "/uploadZhongqi")
	public Map<String, Object> uploadZhongqi(MultipartFile file) {
		String stu_id = GetUserName.getUserName();
		String result = FileUtil.upload(file, stu_id, "pj02");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("message", result);
		return map;
	}
	
	@ResponseBody
	@RequestMapping(value = "/uploadZongjie")
	public Map<String, Object> uploadZongjie(MultipartFile file) {
		String stu_id = GetUserName.getUserName();
		String result = FileUtil.upload(file, stu_id, "pj03");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("message", result);
		return map;
	}
	/**
	 * 下载，stu_status表明是初期还是中期等，用pj01/02/03
	 * @param sbj_status
	 * @param file
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/download")
	public String downloadWord(HttpServletResponse response, @RequestParam("stu_status") String stu_status){
		String stu_id = GetUserName.getUserName();
		return FileUtil.download(response, stu_id, stu_status);
	}
	
	@ResponseBody
	@RequestMapping(value = "/downloadSbj")
	public String downloadSbj(HttpServletResponse response, @RequestParam("teh_id") String teh_id,
			@RequestParam("sbj_id") String sbj_id){
		return FileUtil.download(response, teh_id, sbj_id);
	}
}
